<%
layout("layout.html"){
%>
<div class="page__bd" style="margin-top: 100px;">
    <div class="weui-cells__title">用户登陆</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">手机号码</label>
            </div>
            <div class="weui-cell__bd">
                <input id="phoneInput" type="number" class="weui-input" placeholder="请输入手机号码" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">密码</label>
            </div>
            <div class="weui-cell__bd">
                <input id="passwordInput" type="password" class="weui-input" placeholder="请输入密码" />
            </div>
        </div>
        <div class="weui-btn-area" style="margin-top: 100px;">
            <a id="submitButton" class="weui-btn weui-btn_primary">登陆</a>
        </div>
    </div>
</div>
<div class="js_dialog" id="errorDialog" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd">手机号码或密码错误</div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" id="retryButton" class="weui-dialog__btn weui-dialog__btn_primary">重试</a>
        </div>
    </div>
</div>
<script src="${ctxPath}/js/md5.min.js"></script>
<script src="${ctxPath}/js/net.js"></script>
<script>
    $('#retryButton').click(function() {
        $('#errorDialog').fadeOut(200);
    });
    $('#submitButton').click(function () {
        var user = {
            phone: $('#phoneInput').val(),
            password: $('#passwordInput').val()
        };
        user.password = md5(user.password);
        net().url("${ctxPath}/api/user/login").data(user)
            .success(function (response) {
                if (response.code == 0) {
                    window.location.href = "${ctxPath == '' ? '/' : ctxPath }";
                } else {
                    $('#errorDialog').fadeIn(200);
                }
            })
            .error(function(err) {

            }).post();
    });
</script>
<% } %>